"use strict";
import {
  IndexModel
} from '../models/indexModel';
import widget from '../widget/widget';

const indexController = {
  index() {
    return async(ctx, next) => {
      ctx.body = await ctx.render('index.html', {
        title: 'My Index'
      })
    }
  },
  thumb() {
    return async(ctx, next) => {
      let xpjax = ctx.request.headers['x-pjax'];  // 单页加载
      console.log(xpjax,  widget.thumb);
      /*if (xpjax) {
        ctx.body = widget.thumb;
      } else {*/
        ctx.body = await ctx.render('thumb.html', {
          title: 'My ThumbUp'
        });
      // }
    }
  },
  star() {
    return async(ctx, next) => {
      ctx.body = await ctx.render('star.html', {
        title: 'My Star'
      });
    }
  },
  update() {
    return async(ctx, next) => {
      console.log(ctx.query, ctx.querystring, ctx.request.query, ctx.params);
      let indexM = new IndexModel(ctx);
      ctx.body = await indexM.updateNum(ctx.params);
    }
  }
}

export default indexController;